<?php
namespace app\model;
use think\Db;
use think\Model;

class User extends Model
{
    public static function checkUser($data)
    {
        try{
            $info = User::where('user_name',$data['user_name'])->field('id,user_name,password,nickname,email,role_group,role_detail')->findOrFail()->toArray();
        }catch(\Exception $e){
            return json(['code'=>202,'msg'=>'用户不存在']);
        }
        if(md5($data['password']) == $info['password']){
            unset($info['password']);
            $info2['info']= $info;
            $info2['company'] = Company::field('id,company_name')->find()->toArray();
            $info2['language'] = Language::field('id,title,en_title,zh_short_title,en_short_title')->find()->toArray();
            $info2['site'] = Site::where('language_id',$info2['language']['id'])->where('company_id',$info2['company']['id'])->field('id,site_name,site_url')->find()->toArray();
            session('info',$info2);
            return json(['code'=>200,'msg'=>'登录成功']);
        }else{
            return json(['code'=>202,'msg'=>'密码错误']);
        }
    }
}
